// Editor: myBigPro9/src/services/documentAnalysisService.js
// Action: Create
import api from './api';

const documentAnalysisService = {
  /**
   * 上传Word文档，获取其中所有题目的解析
   * @param {File} documentFile 用户上传的.docx文件
   * @returns {Promise<Array>} 包含多个已解答题目对象的数组
   */
  async solveFromDocument(documentFile) {
    const formData = new FormData();
    formData.append('document', documentFile);

    try {
      const response = await api.post('/api/document/solve-questions', formData, {
        headers: {
          'Content-Type': 'multipart/form-data',
        },
      });
      return response.data;
    } catch (error) {
      console.error('[DocumentAnalysisService] 解析失败:', error);
      const errorMessage = error.response?.data?.error || error.message || '请求服务器失败';
      throw new Error(errorMessage);
    }
  },
};

export default documentAnalysisService;